#include <string>
#include <iostream>
#include "CTagGraph.h"

using namespace std;


#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CTagGraph::CTagGraph()
{
	//branches = NULL;
}

vector<CTagGraph> CTagGraph::GenGraph(int max, int level)
{
	vector<CTagGraph> leaves;
	if (level < max)
	{
		int add = (level < 2) ? 1 : 0;//guarantees at least one branch for first two levels

		//cout << level;
		int c = rand() % (3) + add; //Decrease the # of tags to prevent infinite trees

		for (int i=0; i<c; i++)
		{
			leaves = GenGraph(max, level+1);
		}
	}
	int x = 3;
	return leaves;
}

CTagGraph::~CTagGraph()
{
	branches.clear();
}


CTagGraph* CTagGraph::getBranch(int root, int min)
{
	if (root >= min)
	{
		int randIndex = rand() % ((int)branches.size()+1);

		if ((int)branches.size() == 0)// || randIndex == (int)children.size())//Already given the chance to return this pointer in previous iteration, and don't want to give the entire tree
			return this;

		if (root == 0)
			return &branches[randIndex];
		else
			return branches[randIndex].getBranch(root - 1, min);
	}
	else if ((int)branches.size() != 0)
	{
		int randIndex = rand() % ((int)branches.size()+1);
		return branches[randIndex].getBranch(root - 1, min);
	}
	else
		return NULL;
}